<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<title>用户登录</title>
<c:import url="/ctrl/header"></c:import>
<style type="text/css">
body {
	padding-top: 60px;
	padding-bottom: 40px;
}
</style>
<script>
	function getBytesLength(str) {
		return str.replace(/[^\x00-\xff]/g, 'xx').length;
	};
	function checkLogin() {
		$("#loginname_error").text("");
		$("#loginpwd_error").text("");
		var lname = jQuery.trim($("#loginname").val());
		var lpwd = jQuery.trim($("#loginpwd").val());
		if (lname != '' & lpwd != '') {
			jQuery.ajax({
				url : '/login.json',
				type : 'POST',
				processData : true,
				data : {
					name : lname,
					pwd : lpwd
				},
				success : function(data) {
					if (data && data.ok) {
						var tourl = getUrlParam('tourl');
						if (tourl != null)
							location.href = tourl;
						else
							location.href = '/';
					} else {
						$("#login_error").text("用户名或密码错误！");
						return false;
					}
				},
				error : function(e) {
					$("#login_error").text("用户名或密码错误！");
					return false;
				}
			});
		} else {
			$("#login_error").text("请输入用户名和密码！");
			return false;
		}
		return false;
	}

	function getUrlParam(name) {
		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if (r != null)
			return unescape(r[2]);
		return null;
	}
</script>

</head>
<body>
	<c:import url="/ctrl/top"></c:import>
	<div class="container">
		<div class="span12">
			<h1 style="text-align: center;">用户登录</h1>
		</div>
		<form method="post" action="/login" id="form1">
			<div class="row-fluid" style="text-align: center;">
				<div class="span12">
					<div>
						<div class="field">
							<div>
								用户名&nbsp;<input id="loginname" name="loginname" type="text"
									class="txt-input" maxlength="50" tabindex="1" value="admin" />
							</div>
						</div>
						<div class="field">
							<div>
								密&nbsp;&nbsp;码&nbsp;<input id="loginpwd" name="loginpwd"
									type="password" class="txt-input" tabindex="2" value="123456" />
							</div>
							<div>
								<span id="login_error" class="error"></span>
							</div>
						</div>
						<div class="field">
							<div>
								<input type="submit" name="btnLogin" id="btnLogin"
									onclick="return checkLogin();"
									value="&nbsp;&nbsp;&nbsp;&nbsp;立即登录&nbsp;&nbsp;&nbsp;&nbsp;"
									class="button btn-big btn-orange" />
							</div>
							<div class="field">
								<div>
									还没有账号？ 现在就 <a href="/reg">注册</a>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</form>
		<hr />
		<c:import url="/ctrl/bottom"></c:import>
	</div>

	<c:import url="/ctrl/footer"></c:import>

</body>
</html>
